<template>
    <div class="sub-layout org-detail-content">
        <div class="sub-sidebar">
            <div class="search-bar">
                <div class="search-box">
                    <el-select v-model="search.value" placeholder="搜索用户..." filterable remote :remote-method="searchMethod" :loading="search.loading"
                        @change="searchChange">
                        <el-option v-for="item in search.list" :key="item.id" :label="item.userName" :value="item"></el-option>
                    </el-select>
                    <i class="icon i-search"></i>
                </div>
                <permission class="add" permission-key="salesDept:addSalesDept">
                    <a @click="showEditLayer(0)">
                        <i class="icon i-plus"></i>
                    </a>
                </permission>
            </div>
            <div class="side-nav">
                <tree-view :model="treeData" @on-selected="treeSelected" @on-toggle-expand="getOrgLevel"></tree-view>
            </div>
        </div>
        <div class="sub-main">
            <div class="content">
                <div class="section section-panel">
                    <div class="panel-title">
                        <span class="title">查看用户</span>
                        <div class="title-right">
                            <button class="btn-cancel" @click="goBack">返回</button>
                            <permission permission-key="orgUser:editOrgUser">
                                <router-link :to="{path: '/system/org/edit', query: {userid: userId,code:deptCode,source:sourceType}}">
                                    <button>编辑</button>
                                </router-link>
                            </permission>
                        </div>
                    </div>
                    <div class="panel-content">
                        <div class="form-box" v-if="detail">
                            <div class="form-item">
                                <label class="form-label">用户姓名</label>
                                <div class="form-text" v-text="detail.userName"></div>
                            </div>
                            <div class="form-item">
                                <label class="form-label">邮箱地址</label>
                                <div class="form-text" v-text="detail.email"></div>
                            </div>
                            <div class="form-item">
                                <label class="form-label">职位</label>
                                <div class="form-text" v-text="detail.position?detail.position:'-'"></div>
                            </div>
                            <div class="form-item">
                                <label class="form-label">身份证号</label>
                                <div class="form-text" v-text="detail.identity?detail.identity:'-'"></div>
                            </div>
                            <div class="form-item">
                                <label class="form-label">手机号</label>
                                <div class="form-text" v-text="detail.phone"></div>
                            </div>
                            <div class="form-item">
                                <label class="form-label">入职时间</label>
                                <div class="form-text" v-text="detail.hiredate<0?'-':detail.hiredate"></div>
                            </div>
                            <div class="form-item">
                                <label class="form-label">所属职场</label>
                                <div class="form-text" v-text="detail.theirWork?detail.theirWork:'-'"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 编辑layer -->
        <layer :data="editLayerData" @on-cancel="closeEditLayer" @on-ok="editLayerConfirm">
            <div class="el-form">
                <div class="el-form-item is-required" :class="{'is-error':editLayerData.error}">
                    <label class="el-form-item__label" style="width: 100px;">公司名称</label>
                    <div class="el-form-item__content" style="margin-left: 112px;">
                        <div class="el-input">
                            <input autocomplete="off" type="text" validateevent="true" class="el-input__inner" placeholder="请输入公司名称" v-model="editLayerData.name"
                                @blur="layerInputBlur">
                        </div>
                        <div class="el-form-item__error" v-if="editLayerData.error">请输入公司名称</div>
                    </div>
                </div>
            </div>
        </layer>
    </div>
</template>
<script>
    import './orgDetail.less'
    import orgManage from '@/mixins/orgManage'
    import { formatDate } from '@/mixins/filters'
    export default {
        name: 'orgDetail',
        mixins: [orgManage],
        data() {
            return {
                detail: {}
            }
        },
        computed: {
            userId() {
                return this.$route.query.userid || 0
            },
            deptCode() {
                return this.$route.query.code || 0
            },
            sourceType() {
                return this.$route.query.source || 0
            }
        },
        mounted() {
            this.$store.dispatch('setBreadData', [
                {
                    name: '系统管理'
                },
                {
                    name: '组织架构管理',
                    path: '/system/org'
                },
                {
                    name: '组织架构详情'
                }
            ])
            api.getOrgUser({
                id: this.userId
            }).then(res => {
                res.hiredate = res.hiredate < 0 ? '' : formatDate(res.hiredate, 'yyyy-MM-dd')
                this.detail = res
            }).catch(res => {
                console.log(res)
            })
        },
        methods: {
            // 返回
            goBack() {
                this.$router.go(-1)
            }
        }
    }
</script>